var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var base64 = require('../../utils/Base64.js');
var app = getApp();

var uid = '';
var loginuid = '';

var navtitle = "";
var shareUserName = "";

var ysnbPage = 1;
var ysnbMore = true;
var ysnbGoinMore = false;

var jkPage = 1;
var jkMore = true;
var jkGoinMore = false;

var zpPage = 1;
var zpMore = true;
var zpGoinMore = false;

var mtPage = 1;
var mtMore = true;
var mtGoinMore = false;

var initData = {};
var wxFailAuth = true;

var isAddClassly = true;
var classlyType = 1; //1:作品分类  3:文字分类

Page({
  data: {
    actionSheetHidden: true,
    actionSheetItems: [
      { bindtap: 'release', txt: '近况', link: 'release-jk/release-jk' },
      { bindtap: 'release', txt: '作品', link: 'release-zp/release-zp' },
      { bindtap: 'release', txt: '简介', link: 'release-jj/release-jj' },
      { bindtap: 'release', txt: '媒体', link: 'release-mt/release-mt' },
      { bindtap: 'release', txt: '评论文字', link: 'release-wz/release-wz' },
    ],
      loaddingOK: false,
      wanshan_show:true,
      createMP_show:false,
      curr:{
          ysjCurr:"curr",
          jkCurr:"",
          zpCurr:"",
          wzCurr:"",
          meitiCurr:"",
          appCurr:""
      },
      ysj:{
          ysnb:{
              result:[]
          }
      },
      jk:{
          result:[]
      },
      zp:{
          result:[]
      },
      wzIndex: '',

      mt:{
        result: []
      },
      ysjImgContent:{
          scaleWidth:0
      },
      mtLogo:{},

      isShow:false,
      startTime:0,   
      userInfo: null,
      imgDomain: app.globalData.imgDomain,
      isFriend:4,
      hasShare:false,
      loginCata:false,
      token: '',
      loginuid:'',
      pyq:"http://artartimages.b0.upaiyun.com/2016/1227/19/15941ba95c7.jpg",
      ewm:"http://artartimages.b0.upaiyun.com/2016/1227/19/15941ba95b4.jpg",
      zljl:{},
      ysnb:{},
      cjgz:{},
      ryjx:{},
      gyjz:{},
      cbzz:{},
      gzjl:[],
      jyjl:[],
      userphotos: [],
      isArtist: false,
      loginInfo:{},
      inviteuid: '',
      show_addClass_view:false,
      editClasslyData: '',
      className:'',
      modalHidden: true
  },

  //初始化函数
  onLoad: function (data) {
    wx.showLoading({
      title: '加载中',
    })

    uid = data.uid;
    console.log("init uid = " + uid);

    //是否首先显示 近况／业务资料  页 
    if(data.go && data.go == "dongtai"){
      this.setData({
        curr: {
          ysjCurr: "",
          jkCurr: "curr",
          zpCurr: "",
          wzCurr: "",
          meitiCurr: "",
          appCurr: ""
        }
      });
    }
    //是否是从 别人分享的 页面点进来的
    var inviteuid = data.inviteuid;
    if (inviteuid) {
      this.setData({
        hasShare: true,
        inviteuid: inviteuid
      })
    }

    var that = this;
    if (!uid || uid == "null"){
      //如果传进来的 用户uid为空 或 是 null  则清空一下缓存 重新读取 登录用户数据
      wx.clearStorageSync();
    };
    //调用应用实例的方法获取全局数据
    app.LoginUserInfo(function (res) {
      wxFailAuth = (res == -1);
      if (wxFailAuth) {//用户拒绝授权
        if (!uid || uid == "null") {//没传过来 uid  说明要看登录用户的 个人名片页
          that.setData({
            "isFriend": 10,
            userInfo: {},
            loginInfo: {},
            loaddingOK: true
          });
        }
      } else {//
        var friend = 4;
        loginuid = res.uid;
        if (!uid || uid == "null") {//没传过来 uid  说明要看登录用户的 个人名片页
          uid = loginuid;
          friend = 10;
        }
        if (uid == loginuid) {
          friend = 10;
        }
        
        var cata = (parseInt(res.usercata) > 0) ? true : false;
        that.setData({
          loginInfo: res,
          loginuid: loginuid,
          token: res.token,
          loginCata: cata,
          "isFriend": friend
        });
      }

      that.initData();
    }, inviteuid);

    //初始化值
    ysnbPage = jkPage = zpPage = 1;
    ysnbMore = jkMore = zpMore = true;
	  wx.getSystemInfo({
        success: function(res) {
            that.setData({
                ysjImgContent:{
                    scaleWidth:res.windowWidth
                }
            })
        }
    })
  },

  initData:function(){
    var that = this;
    //设置用户信息
    console.log("aaaa  index uid = " + uid);
    // wx.showToast({
    //   title: '读取用户 ' + uid + " 的数据",
    // })
    if (uid && uid != "null") {
      app.GetUserInfo(uid, function (res) {
        console.log("用户信息数据：", res);
        var tmpis = false;
        if (res.usercataxcx) {
          var usercatatmp = res.usercataxcx.split(',');
          var artarray = [98, 96, 97, 70, 133, 129, 128];
          for (var tmpi = 0; tmpi < usercatatmp.length; tmpi++) {
            for (var tmpii = 0; tmpii < artarray.length; tmpii++) {
              if (artarray[tmpii] == usercatatmp[tmpi]) { tmpis = true; }
            }
          }
        }
        console.log(tmpis);
        var uPhotos = [];
        if (res.photo) {
          uPhotos = res.photo.split(',');
        }
        //更新数据
        that.setData({
          userInfo: res,
          loaddingOK: true,
          userphotos: uPhotos,
          isArtist: tmpis
        })
        //设置导航标题
        shareUserName = res.nickname;
        var navtitle = res.nickname;
        if (res.usercata) {
          navtitle = res.nickname + '·' + res.usercata.split(",")[0];
        }
        if (navtitle) {
          wx.setNavigationBarTitle({
            title: navtitle
          });
        }

        util.api({
          data: {
            "publickey": util.publiccode,
            "ac": "jianjieindex",
            "uid": uid,
            "cuid": loginuid
          },
          success: function (responseData) {
            var zljl = responseData.data.zljl;
            if (zljl != undefined && zljl.minage != undefined) {
              zljl.minYear = zljl.minage.split("-")[0];
            }
            if (zljl != undefined && zljl.maxage != undefined) {
              zljl.maxYear = zljl.maxage.split("-")[0];
            }
            //收藏拍卖
            var cjgz = responseData.data.cjgz;
            if (cjgz != undefined && cjgz.minage != undefined) {
              cjgz.minYear = cjgz.minage.split("-")[0];
            }
            if (cjgz != undefined && cjgz.maxage != undefined) {
              cjgz.maxYear = cjgz.maxage.split("-")[0];
            }
            //艺术年表
            var ysnb = responseData.data.ysnb;
            if (ysnb != undefined && ysnb.minage != undefined) {
              ysnb.minYear = ysnb.minage.split("-")[0];
            }
            if (ysnb != undefined && ysnb.maxage != undefined) {
              ysnb.maxYear = ysnb.maxage.split("-")[0];
            }
            if (ysnb != undefined) {
              for (var i = 0; i < ysnb.info.length; i++) {
                ysnb.info[i].hasBorder = "";
                if (i == ysnb.info.length - 1) {
                  ysnb.info[i].hasBorder = "none";
                }
                var age = ysnb.info[i].age.split("-");
                ysnb.info[i].ageYear = age[0];
                if (age[0] && age[1]) ysnb.info[i].ageMonth = age[1] + "-" + age[2];
                ysnb.info[i].message = ysnb.info[i].message.replace(/\n/g, '\n\n');
                ysnb.info[i].message = ysnb.info[i].message.replace(/&nbsp;/g, '');
              }
            }
            //荣誉奖项
            var ryjx = responseData.data.ryjx;
            if (ryjx != undefined && ryjx.minage != undefined) {
              ryjx.minYear = ryjx.minage.split("-")[0];
            }
            if (ryjx != undefined && ryjx.maxnage != undefined) {
              ryjx.maxYear = ryjx.maxage.split("-")[0];
            }
            if (ryjx != undefined) {
              for (var i = 0; i < ryjx.info.length; i++) {
                ryjx.info[i].hasBorder = "";
                if (i == ryjx.info.length - 1) {
                  ryjx.info[i].hasBorder = "none";
                }
                var age = ryjx.info[i].age.split("-");
                ryjx.info[i].ageYear = age[0];
                if (age[0] && age[1]) ryjx.info[i].ageMonth = age[1] + "-" + age[2];
                // ryjx.info[i].ageMonth = age[1]+"-"+age[2];
                ryjx.info[i].message = ryjx.info[i].message.replace(/\n/g, '\n\n');
                ryjx.info[i].message = ryjx.info[i].message.replace(/&nbsp;/g, '');
              }
            }
            //公益捐赠
            var gyjz = responseData.data.gyjz;
            if (gyjz != undefined && gyjz.minage != undefined) {
              gyjz.minYear = gyjz.minage.split("-")[0];
            }
            if (gyjz != undefined && gyjz.maxage != undefined) {
              gyjz.maxYear = gyjz.maxage.split("-")[0];
            }
            //出版刊登
            var cbzz = responseData.data.cbzz;
            if (cbzz != undefined && cbzz.minage != undefined) {
              cbzz.minYear = cbzz.minage.split("-")[0];
            }
            if (cbzz != undefined && cbzz.maxage != undefined) {
              cbzz.maxYear = cbzz.maxage.split("-")[0];
            }
            //工作经历
            if (responseData.data.gzjl != undefined) {
              var gzjl = responseData.data.gzjl.info;
              console.log("工作经历：", gzjl);
            }
            // gyjz.minYear = gyjz.minage.split("-")[0];
            // gyjz.maxYear = gyjz.maxage.split("-")[0];
            //教育经历
            if (responseData.data.jyjl != undefined) {
              var jyjl = responseData.data.jyjl.info;
            }
            // cbzz.minYear = cbzz.minage.split("-")[0];
            // cbzz.maxYear = cbzz.maxage.split("-")[0];
            that.setData({
              ryjx: ryjx,
              ysnb: ysnb,
              cjgz: cjgz,
              zljl: zljl,
              gyjz: gyjz,
              cbzz: cbzz,
              gzjl: gzjl,
              jyjl: jyjl
            });

          }
        });

        util.api({
          data: {
            "publickey": util.publiccode,
            "ac": "wxcheck"
          },
          success: function (responseData) {
            that.setData({
              isShow: responseData.data.isShow
            });
          }
        });
        //艺术年表
        // this.loadYsnb(1);
        //近况
        that.loadJk(1);
        if (that.data.isArtist) {
          //作品
          that.loadZp(1);
          //文字近况
          that.loadTextIndex();
          //媒体
          that.loadMeitiLogo();
          that.loadMeiti(1);
        }
        wx.hideLoading();
      });

      //获取 双方关注 状态
      if (!wxFailAuth && uid != loginuid) {
        util.api({
          data: {
            "publickey": util.publiccode,
            "ac": "isaction",
            "uid": loginuid,
            "fid": uid
          },
          success: function (responseData) {
            that.setData({
              "isFriend": responseData.data[0].rel
            });
          }
        });
      }
    } else {
      wx.hideLoading();
    }
  },

  reGetUserInfo: function (e) {
    var that = this;
    console.log("reGetUserInfo: ", e);
    if (e == 1){
      // wx.reLaunch({ //用这个会报错fail can not invoke relaunch in background
      wx.redirectTo({
        url: '/pages/index/index?inviteuid=' + that.data.inviteuid
      })
    // } else {
    //   if (!uid || uid == "null") {
    //     wx.redirectTo({
    //       url: '/pages/mail-list/mail-list'
    //     })
    //   }
    }
  },

  addOrRemoveFollow: function(e) {
    if (wxFailAuth) {
      app.reAuthorize(this.reGetUserInfo);
      return;
    }

    var that = this;
    
    var ouid = loginuid;
    var tuid = uid;
    var token = this.data.token;
    var privatekey,ac;
    if(this.data.isFriend == 1 || this.data.isFriend == 2){
        privatekey = utilMd5.hexMD5(ouid+'delaction'+token);
        ac = "delaction";
    }else{
      if (!that.data.loginInfo.usercata || parseInt(that.data.loginInfo.usercata) <= 0) {
          that.setData({
            createMP_show: true
          })  
          return;
        }
        privatekey = utilMd5.hexMD5(ouid+'addaction'+token);
        ac = "addaction";
    }
    util.api({
        data:{
            publickey:util.publiccode,
            ac:ac,
            uid: ouid,
            tuid:tuid,
            privatekey: privatekey
        },
        method:'POST',
        success:function(responseData){
            var data = responseData.data;
            if(data.res === true) {
                if(that.data.isFriend == 1 || that.data.isFriend == 2){
                    app.dialog('移出名片成功', 'success');
                    var friend = (that.data.isFriend == 1? 3: 4);
                    console.log("friend:", friend);
                    that.setData({
                        isFriend: friend,
                    });
                }else{
                    app.dialog('存入名片成功', 'success');
                    var friend = (that.data.isFriend == 3? 1: 2);
                    console.log("friend:", friend);
                    that.setData({
                      isFriend: friend
                    });
                }
            } else {
              if (that.data.isFriend == 1 || that.data.isFriend == 2) {
                app.dialog('移出名片失败', 'loading');
              } else {
                app.dialog('存入名片失败', 'loading');
              }
            }
        }
    });
  },
  //交换名片申请
  addFollow: function (e) {
    if (wxFailAuth) {
      app.reAuthorize(this.reGetUserInfo);
      return;
    }

    var that = this;

    if (!that.data.loginInfo.usercata || parseInt(that.data.loginInfo.usercata) <= 0) {
      that.setData({
        createMP_show: true
      })
      return;
    }

    var ouid = loginuid;
    var tuid = uid;
    var token = this.data.token;
    var privatekey = utilMd5.hexMD5(ouid + 'addaction' + token);
    var ac = "addaction";
      if (!that.data.userInfo.usercata) {
        that.setData({
          createMP_show: true
        })
        return;
      }
    
    util.api({
      data: {
        publickey: util.publiccode,
        ac: ac,
        uid: ouid,
        tuid: tuid,
        privatekey: privatekey
      },
      method: 'POST',
      success: function (responseData) {
        var data = responseData.data;
        console.log("follow: ", data);
        if (data.res === true) {
            app.dialog('申请已发送，等待对方同意', 'success');
            that.setData({
              isFriend: 2
            });
        } else {
          if (data.msg.indexOf('already') >= 0){
            app.dialog('申请已发送，等待对方同意', 'success');
          } else {
            app.dialog(data.msg, '');
          }
        }
      }
    });
  },

  clickImg: function(e){
      // this.setData({
      //     "stv.src":e.currentTarget.dataset.imgsrc,
      //     "stv.display":"true"
      // });
    wx.previewImage({
      current: e.currentTarget.dataset.imgsrc, 
      urls: this.data.userInfo.photosData
    })
  },
  loadYsnb:function(cpage){
      
    var that = this;
      util.api({
        data:{
            publickey:util.publiccode,
            ac:"topiclist",
            postuid:uid,
            topictype:13,
            toporder:1,
            page:cpage,
            num:20
        },
        success:function(responseData){
            var result = responseData.data;
            console.log('page:'+cpage);
            if(result && result.length > 0){
                result.forEach(function(m,i){
                if(m.photos)
                    result[i].photosData = m.photos.split(",");
                //分割年代和月份
                if(result[i].age)
                    var ageArr = result[i].age.split('-');
                
                result[i].ageYear = ageArr[0];
                if(ageArr[1]) {
                    result[i].ageMonth = ageArr[1];
                    if(ageArr[2]) {
                        result[i].ageMonth += '-'+ageArr[2];
                    }
                }

                //处理message
                result[i].message = result[i].message.replace(/\n/g, '\n\n');
                result[i].message = result[i].message.replace(/&nbsp;/g, '');
                });
                
                that.setData({
                    ysj:{
                        ysnb:{
                            result:that.data.ysj.ysnb.result.concat(result)
                        }
                    }
                });
            } else {
                ysnbMore = false;
            }
            ysnbGoinMore = true;
        }
    });
  },
  loadZp:function(cpage){
      var that = this;
    util.api({
        data:{
            publickey:util.publiccode,
            ac:"catalist",
            uid:uid,
            type:1,
            page: cpage
        },
        success:function(responseData){
            var result = responseData.data;
            console.log("作品栏目：", result);
            if(result && result.length > 0) {
                result.forEach(function(m){
                  if(m.name){
                    var names = m.name.split("|");
                    m.chineseName = names[0];
                    m.englishName = names[1];
                  }
                  m.uid = uid;
                  var minYear = m.minage ? m.minage.substring(0, 4) : "";
                  var maxYear = m.maxage ? m.maxage.substring(0, 4) : "";
                  m.minYear = minYear;
                  m.maxYear = maxYear;
                });

                if (cpage > 1){
                  result = that.data.zp.result.concat(result);
                };
                that.setData({
                    zp:{
                        result:result
                    }
                });
            } else {
                zpMore = false;
            }
            zpGoinMore = true;
            
        }
    });
  },
  loadJk:function(cpage){
    var that = this;
    var params = {
      publickey: util.publiccode,
      ac: "topiclist",
      postuid: uid,
      toporder: 1,
      page: cpage,
      num: 10
    }
    console.log("近况请求参数：", params);
    // app.dialog("读取近况数据", 'loading');
    util.api({
        data:params,
        success:function(responseData){
          // app.dialog("读取近况数据完成", 'loading');
            var result = responseData.data; 
            if(result && result.length > 0){
                result.forEach(function(m,i){
                if(m.photos) {
                    result[i].photosData = m.photos.split(",");
                } else {
                    result[i].photosData = [];
                }
                    
                });
                that.setData({
                    jk:{
                        result:that.data.jk.result.concat(result)
                    }
                });
            } else {
                jkMore = false;
            }
            jkGoinMore = true;
        }
    });
  },
  loadTextIndex:function(){
    var that = this;
      util.api({
        data:{
            publickey:util.publiccode,
            ac:"textindex",
            uid:uid,
            cuid:loginuid
        },
        success:function(responseData){
            var result = responseData.data;
            console.log("文字分类：", result);
            if(result && result.info){
              result.info.forEach(function(m,i){
                  var index = m.title.indexOf('|');
                  if(index > 0){
                    result.info[i].cnTitle = m.title.substring(0, index);
                    result.info[i].enTitle = m.title.substring(index+1);
                  } else {
                    result.info[i].cnTitle = m.title;
                  }
                  var age = '';
                  if (result.info[i].minage && result.info[i].minage.length > 4){
                    age = result.info[i].minage.substring(0, 4);
                  }
                  age += '-';
                  if (result.info[i].maxage && result.info[i].maxage.length > 4) {
                    age += result.info[i].maxage.substring(0, 4);
                  }
                  result.info[i].age = age;

                  // var subInfo = result.info[i].info;
                  // for(var j = 0; j < subInfo.length; j++){
                  //   var subInfoItem = subInfo[j];

                  // }
              });
              that.setData({
                  wzIndex: result
              });
            }
            
        }
    });
  },
  loadMeiti: function (cpage) {
    var that = this;
    util.api({
      data: {
        publickey: util.publiccode,
        ac: "topiclist",
        postuid: uid,
        topictype: 17,
        toporder: 1,
        page: cpage,
        num: 10
      },
      success: function (responseData) {
        var result = responseData.data;
        if (result && result.length > 0) {
          result.forEach(function (m, i) {
            if (m.photos)
              result[i].photosData = m.photos.split(",");
          });
          that.setData({
            mt: {
              result: that.data.mt.result.concat(result)
            }
          });
          console.log("媒体：", result);
        } else {
          mtMore = false;
        }
        mtGoinMore = true;
      }
    });
  },
  loadMeitiLogo: function () {
    var that = this;
    util.api({
      data: {
        publickey: util.publiccode,
        ac: "mediaindex",
        uid: uid,
        cuid: loginuid,
      },
      success: function (responseData) {
        var result = responseData.data;
        console.log("媒体logo：", result);
        if (result) {
          that.setData({
            mtLogo: result
          });
        }
        
      }
    });
  },
  loadMore:function(e){
      var cName = e.currentTarget.dataset.con;
      if(cName == "ysj"){
        //   if(ysnbMore && ysnbGoinMore){
        //       ysnbGoinMore = false;
        //       ysnbPage ++;
        //       this.loadYsnb(ysnbPage);
        //   }else{
        //       console.log("艺术年表没有更多了");
        //   }
      }else if(cName == "jk"){
          if(jkMore && jkGoinMore){
              jkGoinMore = false;
              jkPage++;
              this.loadJk(jkPage);
          }else{
              console.log("近况没有更多了");
          }
      }else if(cName == "zp"){
          if(zpMore && zpGoinMore){
              zpGoinMore = false;
              zpPage++;
              this.loadZp(zpPage);
          }else{
              console.log("作品没有更多了");
          }
      } else if (cName == "mt") {
        if (mtMore && mtGoinMore) {
          mtGoinMore = false;
          mtPage++;
          this.loadMeiti(mtPage);
        } else {
          console.log("媒体没有更多了");
        }
      }
  },
  headerCurr: function(e){
      var cName = e.currentTarget.dataset.name;
      if(cName == "ysj"){
          this.setData({
              curr:{
                  ysjCurr:"curr",
                  jkCurr:"",
                  zpCurr:"",
                  wzCurr:"",
                  meitiCurr: "",
                  appCurr: ""
              }
          });
      }else if(cName == "jk"){
          this.setData({
              curr:{
                  ysjCurr:"",
                  jkCurr:"curr",
                  zpCurr:"",
                  wzCurr:"",
                  meitiCurr: "",
                  appCurr: ""
              }
          });
      }else if(cName == "zp"){
          this.setData({
              curr:{
                  ysjCurr:"",
                  jkCurr:"",
                  zpCurr:"curr",
                  wzCurr:"",
                  meitiCurr: "",
                  appCurr: ""
              }
          });
      }else if(cName == "wz"){
          this.setData({
              curr:{
                  ysjCurr:"",
                  jkCurr:"",
                  zpCurr:"",
                  wzCurr:"curr",
                  meitiCurr: "",
                  appCurr: ""
              }
          });
      } else if (cName == "mt") {
        this.setData({
          curr: {
            ysjCurr: "",
            jkCurr: "",
            zpCurr: "",
            wzCurr: "",
            meitiCurr: "curr",
            appCurr: ""
          }
        });
      }else if(cName =="app") {
          this.setData({
              curr:{
                  ysjCurr:"",
                  jkCurr:"",
                  zpCurr:"",
                  wzCurr:"",
                  meitiCurr: "",
                  appCurr:"curr"
              }
          });
      }
  },

  contact: function(e){
    if (wxFailAuth) {
      app.reAuthorize(this.reGetUserInfo);
    } else {
      if (!this.data.loginInfo.usercata || parseInt(this.data.loginInfo.usercata) <= 0) {
        this.setData({
          createMP_show: true
        })
      } else {
        this.goAtherPage(e);
      }
    }
  },

  //保存formId
  submitFormId: function(e){
    if(!wxFailAuth) {
      console.log("formId: ", e.detail.formId);
      app.saveFormId(e.detail.formId);
    }
  },

  goNewCardPage: function(e) {
    if (wxFailAuth) {
      app.reAuthorize(this.reGetUserInfo);
      return;
    }
    console.log("formId: ", e.detail.formId);
    app.saveFormId(e.detail.formId);
    var pageUrl = "/pages/new-card/new-card?uid=" + this.data.loginuid + "&new=1";
    wx.navigateTo({ url: pageUrl})
  },
  goAtherPage: function(e){
      var url = e.currentTarget.dataset.link;
      wx.navigateTo({url: url})
  },

  goNewCardPageRedirect: function (e) {
    if (wxFailAuth) {
      app.reAuthorize(this.reGetUserInfo);
      return;
    }
    console.log("formId: ", e.detail.formId);
    app.saveFormId(e.detail.formId);
    var pageUrl = "/pages/new-card/new-card?uid=" + this.data.loginuid + "&new=1";
    wx.redirectTo({ url: pageUrl })
  },
  goAtherPageRedirect: function(e){
      var url = e.currentTarget.dataset.link;
      wx.redirectTo({url: url})
  },
  //页面分享
  onShareAppMessage: function () {
    return app.sharePage({
      title: shareUserName +"的云名片",
        path: '/pages/index/index?uid='+uid+'&inviteuid='+loginuid
    });
    // return {
    //   title: navtitle,
    //   path: '/pages/index/index?uid=' + uid + '&inviteuid=' + loginuid
    // };
  },
  cancelDialog: function(e){
    console.log("formId: ", e.detail.formId);
    app.saveFormId(e.detail.formId);

      this.setData({
          wanshan_show:false,
          createMP_show: false
      });
  },

  shareToPengyouquan:function(e){
    var shareImgUrl = e.currentTarget.dataset.imgsrc;
    shareImgUrl = base64.encode(shareImgUrl);
    var url = "/pages/share-pengyouquan/share-pengyouquan?imgUrl=" + shareImgUrl;
    wx.navigateTo({ url: url });
  },

  showEWM: function (e) {
    // wx.navigateTo({
    //   url: '/pages/mycard/mycard?uid='+uid,
    // })
    wx.previewImage({
      current: e.currentTarget.dataset.imgsrc,
      urls: [e.currentTarget.dataset.imgsrc]
    })
  },
  showEWMAV: function (e) {
    wx.previewImage({
      current: e.currentTarget.dataset.imgsrc,
      urls: [e.currentTarget.dataset.imgsrc]
    })
  },

  showReleaseMenu:function(){
    this.setData({
      actionSheetHidden:false
    });
  },

  actionSheetTap: function () {
    this.setData({
      actionSheetHidden: !this.data.actionSheetHidden
    })
  },
  actionSheetbindchange: function () {
    this.setData({
      actionSheetHidden: !this.data.actionSheetHidden
    })
  },
  //发布 
  bindrelease: function (e) {
    this.goAtherPage(e);
    this.setData({
      actionSheetHidden: true
    })
  },

  //由参数传过来类型
  addClassAction:function(e){
    classlyType = e.currentTarget.dataset.type;
    isAddClassly = true;
    this.setData({
      editClasslyData: '',
      show_addClass_view: true,
    });
  },
  editZuopinClassAction:function(e) {
    var data = e.currentTarget.dataset.data;
    console.log("class data", data);
    isAddClassly = false;
    classlyType = 1;
    this.setData({
      editClasslyData: data,
      show_addClass_view: true,
    });
  },
  editWenziClassAction: function (e) {
    var data = e.currentTarget.dataset.data;
    console.log("class data", data);
    isAddClassly = false;
    classlyType = 3;
    this.setData({
      editClasslyData: data,
      show_addClass_view: true,
    });
  },

  classlyEdit: function (e) {
    var name = e.currentTarget.dataset.name;
    this.setData({
      className: e.detail.value
    })
  },

  hiddenEditView: function () {
    this.setData({
      show_addClass_view: false,
    });
  },

  editClassAction: function () {
    var className = this.data.className;
    if (!className || className == '中文|English') {
      app.dialog("请输入分类名字", 'loading');
      return;
    }
    // if (className.indexOf('|') <= 0 || className.indexOf('|') == className.length - 1) {
    //   app.dialog("请使用 '|' 分隔中、英文名", 'loading');
    //   return;
    // }
    this.commitClassly();
  },

  commitClassly: function () {
    var that = this;

    var uid = loginuid;//用户id
    var token = this.data.token;//用户token

    var action = "addalbum"
    if(!isAddClassly){
      action = "editalbum"
    }
    var privatekey = utilMd5.hexMD5(uid + action + token);//私钥

    var params = {
      ac: action,
      privatekey: privatekey,
      name: that.data.className,
      uid: uid,
      type: classlyType
    };
    if (!isAddClassly) {
      if(classlyType == 3){
        params.id = that.data.editClasslyData.albumid;
      } else {
        params.id = that.data.editClasslyData.id;
      }
    }
     
    console.log("editalbum params: ", params);
    util.api({
      method: "POST",
      data: params,
      success: function (responseData) {
        var result = responseData.data;
        console.log("edit作品类别：", result);
        if (result.msg) {

        } else {
          app.dialog("操作成功", 'loading');
          if(classlyType == 1){
            that.loadZp(1);
          } else if (classlyType == 3) {
            that.loadTextIndex();
          }
          
          that.hiddenEditView();
        }

      }
    });
  },

  delWenziClassAction: function (e) {
    var data = e.currentTarget.dataset.data;
    console.log("class data", data);
    classlyType = 3;
    this.setData({
      editClasslyData: data,
    });
    this.showModal();
  },
  delZuopinClassAction: function (e) {
    var data = e.currentTarget.dataset.data;
    console.log("class data", data);
    classlyType = 1;
    this.setData({
      editClasslyData: data,
    });
    this.showModal();
  },
  showModal: function () {
    this.setData({
      modalHidden: false
    })
  },
  modalBindaconfirm: function () {
    this.setData({
      modalHidden: true,
    })
    this.delClassly();
  },
  modalBindcancel: function () {
    this.setData({
      modalHidden: true
    })
  },

  delClassly: function () {
    var that = this;

    var uid = loginuid;//用户id
    var token = this.data.token;//用户token
    var privatekey = utilMd5.hexMD5(uid + 'delalbum' + token);//私钥

    var classlyId = that.data.editClasslyData.id;
    if (classlyType == 3){
      classlyId = that.data.editClasslyData.albumid;
    }

    var params = {
      ac: "delalbum",
      privatekey: privatekey,
      uid: uid,
      id: classlyId,
      type: classlyType
    }
    console.log("editalbum params: ", params);
    util.api({
      method: "POST",
      data: params,
      success: function (responseData) {
        var result = responseData.data;
        console.log("del作品类别：", result);
        if (result.msg) {

        } else {
          app.dialog("删除成功", 'loading');
          if (classlyType == 1) {
            that.loadZp(1);
          } else if (classlyType == 3) {
            that.loadTextIndex();
          }
        }
      }
    });
  },
})
